home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
015
/
hpstuff.arc
/
HPXFER.C
< prev
next >
Wrap
Text File
|
1987-02-11
|
4KB
|
139 lines
/*======================================================================*\
|| HPXFER Rip Toren ||
|| POB 674 ||
|| Columbia, MD 21045||
|| ||
|| Will transfer a file of HP Laserjet commands down the LPT line ||
|| to the printer. ||
|| A line beginning with '@' is a file name of a binary image to ||
|| be sent as is. ||
|| ||
|| all chacacters after '~' will not be transfered. ||
|| arg1 is the file name ||
|| ||
\*======================================================================*/
#include "stdio.h"
#include "stdlib.h"
char inline[256] , *p, *q, *r;
int ret,lc;
FILE *inf, *prt, *incl;
main (argc,argv)
int argc;
char *argv[];
{
puts ("HP LaserJet XFER program\n");
if (argc == 1 )
{
puts (" No input filename supplied !");
puts (" ");
puts (" Standard form is 'HPXFER fn'");
puts (" where 'fn' is the file name to transfer");
puts (" if the file is not found, the extension");
puts (" of '.HPX' is appended and tried again.");
exit (1);
}
strcpy (inline,argv[1]); /* get the file name */
if ((inf = fopen (inline,"rb")) == NULL)
{ /* file not found */
strcat (inline,".HPX");
if ((inf = fopen (inline,"rb")) == NULL)
{ /* that file not found also */
puts (" ");
puts ("FILE NOT FOUND!");
exit(1);
}
}
printf ("File being processed is %s\n",inline);
/*-------------------------------------------------------------------*\
| file is now open |
\*-------------------------------------------------------------------*/
/*-------------------------------------------------------------------*\
| Now open the printer |
\*-------------------------------------------------------------------*/
prt = fopen ("PRN", "wb");
if (prt == NULL)
{
puts ("Printer failed to open");
exit (1);
}
setnbf (prt);
puts ("here we go!");
lc = 0;
for (;;)
{
memset (inline,'\0',255);
r = fgets (inline,255,inf);
if (ret=ferror(inf))
{
printf ("FERROR %d\n",ret);
}
if (feof(inf))
{
puts ("\nEOF");
fclose(inf);
fclose(prt);
exit (0);
}
printf ("%4d%c%c%c%c",++lc,0x08,0x08,0x08,0x08);
p = inline; /* set the step pointer */
for (;*p;p++) if (*p == '~') *p = '\0';
p = inline;
if (*p == '@') print_incl(p);
else
/* print the character */
for ( ; *p ; p++) fprintf (prt,"%c",*p);
}
}
/*===========================================================================*\
|| Transfer the binary image . ||
\*===========================================================================*/
#define BUF_S 32000
print_incl (p)
char *p;
{
char *bf ;
int i,eol;
eol = strlen (p);
if ((eol) && (p[eol-2] == 0x0d)) /* some characters in here */
/* and a CRLF */
{
*(p+eol-2) = '\0'; /* overlay 0x0d 0x0a with terminator */
}
printf ("\nIncluding [%s]\n",p+1);
incl = fopen(p+1,"rb");
if (incl == NULL) return;
bf = malloc (BUF_S);
if (bf == NULL)
{
printf ("No space for file buffer \n");
return;
}
for (;;)
{
i = fread (bf,1,BUF_S,incl);
fwrite (bf,1,i,prt);
if (i != BUF_S) break;
}
fclose (incl);
}